package com.bocloud.cmp.dao;

import java.util.List;
import java.util.Map;

import com.bocloud.cmp.entity.resource.Server;
import com.bocloud.cmp.model.RackDevice;
import com.bocloud.common.model.Param;
import com.bocloud.common.model.SimpleBean;
import com.bocloud.database.core.intf.GenericDao;

/**
 * 主机抽象DAO接口
 * 
 * @author wei wei
 * @version 1.0
 * @since 2016.02.27
 */
public interface ServerDao extends GenericDao<Server, Long> {

	/**
	 * 查询主机详细
	 * 
	 * @param id
	 *            the id
	 * @return the server
	 * @throws Exception
	 */
	public Server query(Long id) throws Exception;

	/**
	 * 查询所有虚拟机
	 * 
	 * @return
	 * @throws Exception
	 */
	public List<Server> queryAll() throws Exception;

	/**
	 * 查询主机列表
	 * 
	 * @param page
	 *            the page
	 * @param rows
	 *            the rows
	 * @param params
	 *            the params
	 * @param sorter
	 *            the sorter
	 * @return the result
	 * @throws Exception
	 */
	public List<Server> list(int page, int rows, List<Param> params, Map<String, String> sorter) throws Exception;

	/**
	 * 查询主机简易列表
	 * 
	 * @param params
	 *            the params
	 * @param sorter
	 *            the sorter
	 * @return the bean
	 * @throws Exception
	 */
	public List<SimpleBean> list(List<Param> params, Map<String, String> sorter) throws Exception;

	/**
	 * 设置空闲主机
	 * 
	 * @param id
	 *            the id
	 * @param userId
	 *            the user id
	 * @return
	 * @throws Exception
	 */
	public boolean release(Long id, Long userId) throws Exception;

	/**
	 * 设置归属主机
	 * 
	 * @param rackDevice
	 *            the rackDevice
	 * @param userId
	 *            the user id
	 * @return
	 * @throws Exception
	 */
	public boolean belong(RackDevice rackDevice, Long userId) throws Exception;

	/**
	 * 查询空闲主机列表
	 * 
	 * @return the server list
	 * @throws Exception
	 */
	public List<Server> listFree() throws Exception;

	/**
	 * 查询符合条件的数据数量
	 * 
	 * @param params
	 *            the params
	 * @return count
	 * @throws Exception
	 */
	public int count(List<Param> params) throws Exception;

	/**
	 * 删除主机
	 * 
	 * @param id
	 *            the id
	 * @param userId
	 *            the user id
	 * @return
	 * @throws Exception
	 */
	public boolean remove(Long id, Long userId) throws Exception;

	/**
	 * 隔离主机
	 * 
	 * @param id
	 *            the id
	 * @param userId
	 *            the user id
	 * @return
	 * @throws Exception
	 */
	public boolean isolate(Long id, Long userId) throws Exception;

	/**
	 * 恢复主机
	 * 
	 * @param id
	 *            the id
	 * @param userId
	 *            the user id
	 * @return
	 * @throws Exception
	 */
	public boolean recover(Long id, Long userId) throws Exception;

	/**
	 * 检查服务器IP是否存在
	 * 
	 * @param ip
	 *            the manager ip
	 * @return
	 * @throws Exception
	 */
	public boolean exists(String ip) throws Exception;

	/**
	 * 获取机房或机柜下的没有被分配资源池或集群的服务器
	 * 
	 * @param id
	 *            the id
	 * @param clazz
	 *            the class type
	 * @return
	 * @throws Exception
	 */
	public List<Server> listFreeNode(Long id, Class<?> clazz) throws Exception;

	/**
	 * 获取机房或机柜下的没有被分配资源池或集群的服务器
	 * 
	 * @param id
	 *            the id
	 * @param clazz
	 *            the class type
	 * @return
	 * @throws Exception
	 */
	public List<Server> listFreeManager(Long id, Class<?> clazz) throws Exception;

	/**
	 * 通过IP获取服务器消息
	 * 
	 * @param ip
	 *            the manager ip
	 * @return
	 * @throws Exception
	 */
	public Server get(String ip) throws Exception;

	/**
	 * 根据数据中心ID获取所有IP
	 * 
	 * @param dcId
	 * @return
	 * @throws Exception
	 */
	public List<String> DcIps(Long dcId) throws Exception;

	/**
	 * 获取所有的IP
	 * 
	 * @return
	 * @throws Exception
	 */
	public List<String> ips() throws Exception;

	/**
	 * 根据机柜ID获取所有IP
	 * 
	 * @param rackId
	 * @return
	 * @throws Exception
	 */
	public List<String> rackIps(Long rackId) throws Exception;

	/**
	 * 根据机房ID获取所有IP
	 * 
	 * @param roomId
	 * @return
	 * @throws Exception
	 */
	public List<String> roomIps(Long roomId) throws Exception;

	/**
	 * 根据数据中心ID获取所有IP
	 * 
	 * @param roomId
	 * @return
	 * @throws Exception
	 */
	public List<String> dcIps(Long roomId) throws Exception;

	/**
	 * 根据集群ID获取所有计算节点IP
	 * 
	 * @param clusterId
	 * @return
	 * @throws Exception
	 */
	public List<String> nodeIps(Long clusterId) throws Exception;

	/**
	 * 根据集群ID获取所有计算管理节点IP
	 * 
	 * @param clusterId
	 * @return
	 * @throws Exception
	 */
	public List<String> managerIps(Long clusterId) throws Exception;

	public List<RackDevice> positions(Long rackId, String sorter) throws Exception;

	/**
	 * 获取所有物理主机的uuid和ip
	 * <p>
	 * 使用SNMP自动发现采集对象时使用
	 * </p>
	 * 
	 * @author sxp
	 * @since V1.0 Dec 5, 2016
	 */
	public List<Map<String, String>> getAll4Snmp() throws Exception;

	public List<Server> listByDataCenter(Long dcId) throws Exception;

	public List<Server> listByRoom(Long roomId) throws Exception;

	public List<Server> listByRack(Long rackId) throws Exception;
}
